﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entity;
using Controller;

namespace Web
{
    public partial class CreateVendor : System.Web.UI.Page
    {

        Helper helper = new Helper();
        VendorEntity vendorEntity = new VendorEntity();
        VendorController vendorController = new VendorController();
        protected void Page_Load(object sender, EventArgs e)
        {
            this.PreRender += new EventHandler(UpdateFlashMessage);
        }
        private void UpdateFlashMessage(object sender, EventArgs e)
        {
            helper.ShowFlashMessage(FlashMessageLabel);
        }

        protected void SubmitButton_Click(object sender, EventArgs e)
        {
            vendorEntity = new VendorEntity();

            vendorEntity.Name = NameTextBox.Text.Trim();
            vendorEntity.ShortName = ShortNameTextBox.Text.Trim();
            vendorEntity.Address = ShortNameTextBox.Text.Trim();
            vendorEntity.Phone = PhoneTextBox.Text.Trim();
            vendorEntity.Fax = FaxTextBox.Text.Trim();
            vendorEntity.Email = EmailTextBox.Text.Trim();
            vendorEntity.ContactPerson = ContactPersonTextBox.Text.Trim();
            vendorEntity.ZipCode = ZipCodeTextBox.Text.Trim();
            vendorEntity.Number = Convert.ToInt32(NumberTextBox.Text.Trim());
            vendorEntity.Code = CodeTextBox.Text.Trim();
            vendorEntity.Remark = RemarkTextBox.Text.Trim();
            bool result = vendorController.AddVendor(vendorEntity);
            if (result == true)
            {
                Session["FlashMessage"] = "Success: Create Customer Successful!";
                Session["FlashMessageType"] = "success";
            }
            else
            {
                Session["FlashMessage"] = "Error: Create Customer unsuccessful!";
                Session["FlashMessageType"] = "error";
            }

        }


        protected void CancelButton_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/VendorList.aspx");
        }
    }
}